package com.gsm.company.service;

import com.gsm.common.utils.IdWorker;
import com.gsm.company.dao.CompanyDao;
import com.gsm.domain.company.Company;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Description: java类作用描述
 * @Author: gaoshengmin
 * @CreateDate: 2020/2/7$ 11:39$
 * @UpdateUser: gaoshengmin
 * @UpdateDate: 2020/2/7$ 11:39$
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Service
public class CompanyService {

    @Autowired
    private CompanyDao  companyDao;

    @Autowired
    private IdWorker idWorker;

    public void add(Company company){
         String id = idWorker.nextId()+"";
        company.setId(id);
        company.setAuditState("1");
        company.setState(1);
        company.setCreateTime(new Date());
        companyDao.save(company);
    }




    public void update(Company company){
        Company temp = companyDao.findById(company.getId()).get();
        temp.setName(company.getName());
        temp.setCompanyPhone(company.getCompanyPhone());
        companyDao.save(temp);
    }


    public void deleteById(String id){
        companyDao.deleteById(id);
    }

    public Company findById(String id){
        return companyDao.findById(id).get();
    }

    public List<Company> findAll(){
        return companyDao.findAll();
    }


}
